﻿using SvgApplication.Authorization;
using SvgApplication.Data.Implementation;
using SvgApplication.Data.Model;
using SvgApplication.Data.Model.Interfaces;
using SvgApplication.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SvgApplication.Controllers
{
    [RoleAuthorizationAttribute(Modules = UserRoles.RegularUser)]
    public class DetailsController : AuthorizationControllerBase
    {
        IUserRepository userRepository;

        public DetailsController()
            : this(new UserRepository())
        {

        }

        public DetailsController(IUserRepository userRepository)
        {
            this.userRepository = userRepository;
        }

        //
        // GET: /Details/

        public ActionResult Index()
        {
            int count = 0;
            var allUsers = userRepository.GetAll().Where(p => p.Role == (byte)UserRoles.RegularUser);
            var model = new DetailsModel()
            {
                User = new User()
                {
                    Id = CurrentUser.UserID,
                    Username = CurrentUser.UserName
                },
                Users = BuildSelectedParamsList(allUsers.ToList())


            };
            return View(model);
        }

        private List<SelectListItem> BuildSelectedParamsList(List<User> selectedParams)
        {
            var dropdownList = new List<SelectListItem>();
            foreach (var item in selectedParams)
            {
                var sli = new SelectListItem
                {
                    Value = (item.Id).ToString(),
                    Text = item.Username
                };
                dropdownList.Add(sli);

            }
            return dropdownList;
        }
    }
}
